#pragma once

#ifndef _ACTOR_SERVER_H_
#define _ACTOR_SERVER_H_

#include <memory>
#include <functional>
#include <map>
#include "TcpServer.h"
#include "as_address.h"
#include "mailpos.h"
#include "as_callback.h"

class ByteBuffer;
typedef std::shared_ptr<ByteBuffer> ByteBufferPtr;


namespace as
{
namespace net
{
class EpollWatch;
class TcpConnection;
typedef std::shared_ptr<TcpConnection> TcpConnectionPtr;
}

namespace md
{


class ActorServer : public as::net::TcpServer
{
public:
	typedef std::function<void(ByteBufferPtr&, int)> ActorMsgCallback;
	ActorServer(as::net::EpollWatch *ep, as::net::Address &serverAddr, const char *name, int pri_key = 0);
	virtual ~ActorServer();
	void HandleMsg(as::net::TcpConnectionPtr &conn, ByteBufferPtr &buf, int size);
	void SetActorMsgCb(ActorMsgCallback fun);

private:
	const int pri_key_;
	ActorMsgCallback actor_msg_fun_;
	std::map<int, as::net::TcpConnectionPtr> conn_map_;
};















	}
}

#endif